﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Xml;
using System.Xml.Linq;

namespace CMSE.Extensions.Vimeo
{
    public class VimeoVideo
    {

        private XDocument videoInformation;

        private string _title;
        private string _url;

        private string _description;
        private int _duration;

        private string _thumbnailLarge;
        private string _thumbnailMedium;
        private string _thumbnailSmall;

        private string _keywords;
        private string _uploader;

        private string _height;
        private string _width;

        public VimeoVideo(string videoData)
        {

            try
            {
                videoInformation = XDocument.Parse(videoData);
            }
            catch { }

            var vimeoVideoData = from video in videoInformation.Descendants("video")
                                 select video;
            foreach (var video in vimeoVideoData)
            {
                _title = video.Element("title").Value;
                _url = video.Element("url").Value;
                _duration = Convert.ToInt32(video.Element("duration").Value);

                _description = video.Element("description").Value;

                _thumbnailLarge = video.Element("thumbnail_large").Value;
                _thumbnailMedium = video.Element("thumbnail_medium").Value;
                _thumbnailSmall = video.Element("thumbnail_small").Value;

                _uploader = video.Element("user_name").Value;

                _width = video.Element("width").Value;
                _height = video.Element("height").Value;

                _keywords = video.Element("tags").Value;
            }




        }

        public string Url
        {
            get { return _url; }
            set { _url = value; }
        }



        public string Width
        {
            get { return _width; }
            set { _width = value; }
        }


        public string Height
        {
            get { return _height; }
            set { _height = value; }
        }


        public string Uploader
        {
            get { return _uploader; }
        }


        public string Keywords
        {
            get { return _keywords; }
        }


        public string ThumbnailSmall
        {
            get { return _thumbnailSmall; }
        }


        public string ThumbnailMedium
        {
            get { return _thumbnailMedium; }
        }


        public string ThumbnailLarge
        {
            get { return _thumbnailLarge; }
        }


        public int Duration
        {
            get { return _duration; }
        }


        public string Description
        {
            get { return _description; }
        }


        public string Title
        {
            get { return _title; }
        }

    }
}
